package com.mjf.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池
 */
public class CreateThreadWithThreadPool {
    public static void main(String[] args) {

        //创建一个包含10个线程的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(10);
//     ExecutorService executorService = Executors.newSingleThreadExecutor();

        for (int i = 0; i < 12; i++) {
            executorService.execute(() -> {
                System.out.println(Thread.currentThread().getName());
            });
        }

        // 关闭线程池
        executorService.shutdown();

    }
}
